<template>
  <!-- 分包商分子公司汇总查看 -->
  <div class="e-form">
    <div class="tabs" v-if="Object.keys(basicFormData).length != 0">
      <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
        <!-- 基本信息 -->
        <el-tab-pane
          label="基本信息"
          name="baseInfo"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="分包商汇总"
          name="subcontractorCollect"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="年度动态惩罚查询表"
          name="punishment"
          :disabled="clickTabFlag"
        ></el-tab-pane>
        <el-tab-pane
          label="评价情况统计表"
          name="orgCollect"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <el-tab-pane
          label="附件信息"
          name="accessory"
          :disabled="clickTabFlag"
        ></el-tab-pane>

        <div>
          <!-- 基本信息 -->
          <div id="baseInfoCon" class="con">
            <div class="e-form">
              <div class="tabs">
                <div class="tabs-title" id="baseInfo">基本信息</div>
                <div style="width: 100%" class="form">
                  <el-form :model="basicFormData" label-width="150px">
                       <BillTop title="分子公司汇总详情" @cancel="handleClose"></BillTop>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="汇总日期">
                          {{basicFormData.billDate}}
                          <!-- <el-date-picker
                            style="width: 300px"
                            v-model="basicFormData.collectDate"
                            type="date"
                            placeholder="选择日期"
                            :clearable="false"
                          >
                          </el-date-picker> -->
                        </el-form-item>
                      </el-col>

                      <el-col :span="12">
                        <el-form-item label="汇总时间区">
                          {{ basicFormData.summartDate }}
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="评价机构"
                          >{{ basicFormData.evaluateOrg }}
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="状态">
                           {{ ['草稿','审核中','已审核','已关闭'][basicFormData.state] }}
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-form-item label="上级机构"
                        >{{ basicFormData.superiorsOrg }}
                      </el-form-item>
                    </el-row>
                    <el-form-item label="备注"
                      >
                      {{basicFormData.remark}}

                    </el-form-item>
                  </el-form>
                </div>
              </div>

            </div>

            <!-- ------------------------------------------------------------------------------------- -->
          </div>

          <!-- 分包商汇总 -->
          <div id="subcontractorCollectCon" class="con">
            <div class="tabs-title" id="subcontractorCollect">分包商汇总</div>
            <div class="e-table">
              <el-table
                ref="multipleTable"
                :data="subDtlList"
                tooltip-effect="dark"
                style="width: 100%"
                class="table"
                :max-height="$store.state.tableHeight"
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }"
                @selection-change="handleSelectionChange"
                v-sortTable="{ 'tableData': subDtlList, '_this': this, 'ref': 'multipleTable' }"
              >
                <el-table-column type="selection" width="50"> </el-table-column>
                <el-table-column label="序号" width="50"> </el-table-column>
                <el-table-column
                  prop="outerName"
                  label="分包商名称"
                  width="150"
                >
                 <template slot-scope="scope">
            <span
              @click="articulars(scope.row.dtlId)"
              style="color: blue; cursor: pointer"
            >
              {{ scope.row.outerName }}
            </span>

          </template>
                </el-table-column>
                <el-table-column label="评价等级" width="500">
                  <el-table-column label="分（子）公司下一级单位" width="500">
                    <el-table-column
                      label="合同1"
                      width="100"
                      prop="contractOne"
                    >
                    </el-table-column>
                    <el-table-column
                      label="合同2"
                      width="100"
                      prop="contractTwo"
                    >
                    </el-table-column>
                    <el-table-column
                      label="合同3"
                      width="100"
                      prop="contractThree"
                    >
                    </el-table-column>
                    <el-table-column label="合同N" width="100" prop="contractN">
                    </el-table-column>
                    <el-table-column label="合计" width="100" prop="total">
                    </el-table-column>
                    <el-table-column
                      label="评价合同数"
                      width="100"
                      prop="evaluateQuantity"
                    >
                    </el-table-column>
                  </el-table-column>
                </el-table-column>
                <el-table-column
                  prop="evaluateSocre"
                  label="动态评价奖励分数"
                  width="150"
                >
                </el-table-column>
                <el-table-column
                  prop="evaluateTotalSocre"
                  label="评价分数"
                  width="200"
                  show-overflow-tooltip
                >
                </el-table-column>
                <el-table-column
                  prop="evaluateGrade"
                  label="评价等级"
                  width="250"
                  show-overflow-tooltip
                >
                </el-table-column>
                <el-table-column
                  prop="evaluateOpinion"
                  label="评价意见"
                  width="150"
                  show-overflow-tooltip
                >
                </el-table-column>
              </el-table>

            </div>
          </div>
          <!-- 年度动态惩罚查询表 -->
          <div id="punishmentCon" class="con">
            <div class="tabs-title" id="punishment">年度动态惩罚查询表</div>
            <div class="e-table">
              <el-table
                :data="punishmentData"
                border
                ref="table"
                class="table"
                style="width: 100%"
                @cell-mouse-enter="cellMouseEnter"
                :max-height="$store.state.tableHeight"
                @cell-mouse-leave="cellMouseLeave"
                :cell-class-name="cellClsNm"
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }"
                v-sortTable="{ 'tableData': punishmentData, '_this': this, 'ref': 'table' }"
              >
                <el-table-column prop="manageOrgName" label="评价管理机构" width="200">
                </el-table-column>
                <el-table-column prop="outerName" label="分包商名称" width="200">
                </el-table-column>
                <el-table-column prop="creditCode" label="统一社会信用代码" width="200">
                </el-table-column>
                <el-table-column prop="e" label="评价日期" width="200">
                </el-table-column>
                <el-table-column prop="result" label="评价结论" width="200">
                </el-table-column>
                <el-table-column prop="startDate" label="开始日期" width="200">
                </el-table-column>
                <el-table-column prop="endDate" label="结束日期" width="200">
                </el-table-column>
              </el-table>

            </div>
          </div>
          <!-- 评价情况统计表 -->
          <div id="orgCollectCon" class="con">
            <div class="tabs-title" id="orgCollect">评价情况统计表</div>
            <div class="e-table">
              <el-table
                :data="tableData"
                border
                style="width: 100%"
                class="table"
                ref="table"
                :max-height="$store.state.tableHeight"
                @cell-mouse-enter="cellMouseEnter"
                @cell-mouse-leave="cellMouseLeave"
                :cell-class-name="cellClsNm"
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }"
                v-sortTable="{ 'tableData': tableData, '_this': this, 'ref': 'table' }"
              >
                <el-table-column type="selection" width="60"> </el-table-column>
                <el-table-column prop="a" label="序号" width="60">
                </el-table-column>
                <el-table-column prop="b" label="机构" width="200">
                </el-table-column>
                <el-table-column prop="c" label="第一季度">
                  <el-table-column
                    prop="c-1"
                    label="应评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="c-2"
                    label="实评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="c-3"
                    label="未评合同数"
                    width="100"
                  ></el-table-column>
                </el-table-column>
                <el-table-column prop="d" label="第二季度">
                  <el-table-column
                    prop="d-1"
                    label="应评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="d-2"
                    label="实评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="d-3"
                    label="未评合同数"
                    width="100"
                  ></el-table-column>
                </el-table-column>
                <el-table-column prop="e" label="第三季度" width="200">
                  <el-table-column
                    prop="e-1"
                    label="应评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="e-2"
                    label="实评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="e-3"
                    label="未评合同数"
                    width="100"
                  ></el-table-column>
                </el-table-column>
                <el-table-column prop="f" label="第四季度" width="200">
                  <el-table-column
                    prop="f-1"
                    label="应评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="f-2"
                    label="实评合同数"
                    width="100"
                  ></el-table-column>
                  <el-table-column
                    prop="f-3"
                    label="未评合同数"
                    width="100"
                  ></el-table-column>
                </el-table-column>
              </el-table>
              <div style="display: flex; margin-top: 20px">
                <div style="width: 50%">评价得分: {{ 111 }}</div>

                <div style="width: 50%">综合评价: {{ 222 }}</div>
              </div>
              <div style="display: flex; margin-top: 20px">
                <div style="width: 50%">项目负责人: {{ 111 }}</div>

                <div style="width: 50%">检查人: {{ 222 }}</div>
              </div>
            </div>
          </div>

          <!-- 附件信息 -->
          <div id="accessoryCon" class="con">
            <div class="tabs-title" id="accessory">附件信息</div>
            <div class="e-table">
              <div class="top">
                <div class="left">
                  <el-button size="mini">添加</el-button>
                  <!-- <el-button size="mini">删除</el-button> -->
                </div>
              </div>
              <el-table
                :data="tableData"
                border
                ref="table"
                style="width: 100%"
                class="table"
                :max-height="$store.state.tableHeight"
                @cell-mouse-enter="cellMouseEnter"
                @cell-mouse-leave="cellMouseLeave"
                :cell-class-name="cellClsNm"
                :header-cell-style="{ textAlign: 'center' }"
                :cell-style="{ textAlign: 'center' }"
                v-sortTable="{ 'tableData': tableData, '_this': this, 'ref': 'table' }"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column prop="a1" label="序号" width="100">
                </el-table-column>
                <!-- <el-table-column prop="a2" label="类型" width="150">
                </el-table-column> -->

                <el-table-column prop="a" label="文件名称" width="200">
                </el-table-column>
                <el-table-column prop="b" label="文件大小(kb)" width="200">
                </el-table-column>
                <el-table-column prop="c" label="上传时间" width="200">
                </el-table-column>
                <el-table-column prop="d" label="上传人" width="200">
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </el-tabs>
    </div>
    <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
    <div class="buttons">

      <el-button size="small" @click="handleClose">取消</el-button>
    </div>
  </div>
</template>

<script>
// import { mapState } from 'vuex'
import $ from 'jquery'
import '@/utils/jquery.scrollTo.min'

export default {
    data () {
        return {
            tabsName: 'baseInfo',
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: '',
            },
            tableData: [],
            punishmentData: [], //年度惩罚表
            subDtlList: [], //分包商汇总明细
            value: '',
            textarea: '',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //基本信息表单数据
            basicFormData: {
                billDate: '', //汇总日期
                summartDate: '', //汇总时间区
                evaluateOrg: '', //评价机构
                state: '', //状态
                superiorsOrg: '', //上级机构
                remark: '', //备注
            },
        }
    },
    computed: {

        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
    },
    components: {},
    created () {
        this.id = this.$route.query.id
        this.getBasicData() //进入页面就获取基本信息数据
        this.getPunishment()
    },
    mounted () {
    // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()

        // 保存所有tabName
        const arr = [
            'baseInfo',
            'subcontractorCollect',
            'punishment',
            'orgCollect',
            'accessory',
        ]
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const $item = document.getElementById(item)
                    let itemTop = null
                    if ($item) {
                        itemTop = $item.offsetTop
                    }
                    return itemTop
                })
            }
            const scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth
            this.screenHeight = document.documentElement.clientHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        })
    },
    methods: {
    //获取基本信息数据
        getBasicData () {
            //发ajax
            this.$Ajax
                .httpGet({
                    url: '/outer/summary/findById',
                    params: {
                        id: this.id,
                    },
                })
                .then(res => {
                    this.basicFormData = res
                    this.subDtlList = res.subDtlList
                    console.log('6666', res.subDtlList)
                })
        },
        //获取年度动态惩罚表
        getPunishment () {
            this.$Ajax
                .httpGet({
                    url: '/outer/rewardsorpunishment/annualPunish',
                    params: {
                        timeInterval: '2008-01-01——2022-01-01',
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                }).then(res => {
                    this.punishmentData = res
                    console.log('?>>>>>',  this.getPunishment)

                })
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('evaluateCon')) {
                    const lastConHeight =
            document.getElementById('evaluateCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    console.log('this.lastConHeight', this.lastConHeight)
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        //分包商汇总列表
        articulars (dtlId) {
            console.log(dtlId)
        },
        //删除
        delData () {
            this.$Ajax
                .httpGet({
                    url: '/outer/summary/delete',
                    params: {
                        id: this.id,
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                })
                .then(res => {
                    this.$message({
                        showClose: true,
                        type: 'success',
                        message: res.message,
                    })
                    this.$router.push('/collectEvaluate')
                })
        },

        handleFullScreen () {
            this.fullscreen = !this.fullscreen
        },
        //取消
        handleClose () {
            this.$router.push('./collectEvaluate')
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        onChangeTab (e) {
            console.log('clickTabFlag: ', this.clickTabFlag)
            $.scrollTo(`#${e.name}`, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
    },
}
</script>

<style lang="scss" scoped>
.buttons {
  left: 0;
}
.e-form {
  margin-bottom: 80px;
  padding: 0 20px;
  .tabs-title::before {
    content: "";
    height: 22px;
    width: 8px;
    border-radius: 40px;
    background-color: #2e61d7;
    display: block;
    position: absolute;
    left: 20px;
    margin-right: 20px;
  }
}

.e-table {
  background: #fff;
}
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 6px; // 横向滚动条
  height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #ddd;
  border-radius: 5px;
}

.el-tab-pane {
  margin-left: -10px;
}
::v-deep.el-upload-dragger {
  height: 90px;
  margin-left: 300px;
}
</style>